jQuery.fn.extend({
    //上游企业机构    size：下拉列表最大数量
    syCombobox: function (size) {
        var combobox = $(this).combobox({
            valueField: 'id',
            textField: 'qc',
            mode: 'remote',
            loader: function (param, success, error) {
                var q = param.q || '';
                if (q.length <= 1) {
                    return false
                }
                $.ajax({
                    url: $.webPath() + '/organ/qyjg/findAllSy',
                    dataType: 'json',
                    type: 'POST',
                    data: {
                        maxRows: size,
                        name_startsWith: q
                    },
                    success: function (data) {
                        $(combobox).combobox("loadData", data);
                    },
                    error: function () {

                    }
                });
            }
        });
    },
    //下游企业    size：下拉列表最大数量
    xyCombobox: function (size) {
        var combobox = $(this).combobox({
            valueField: 'id',
            textField: 'qc',
            mode: 'remote',
            loader: function (param, success, error) {
                var q = param.q || '';
                if (q.length <= 1) {
                    return false
                }
                $.ajax({
                    url: $.webPath() + '/organ/qyjg/findAllXy',
                    dataType: 'json',
                    type: 'POST',
                    data: {
                        maxRows: size,
                        name_startsWith: q
                    },
                    success: function (data) {
                        $(combobox).combobox("loadData", data);
                    },
                    error: function () {

                    }
                });
            }
        });
    },
    //type:自购物资计划Zgwzjh  统配物资计划Tpwzjh
    wzjhForHtCombogrid: function (paramOptions) {
        paramOptions.page = (typeof paramOptions.page == "undefined") ? 10 : paramOptions.page;
        paramOptions.ssgsId = (typeof paramOptions.ssgsId == "undefined") ? null : paramOptions.ssgsId;
        paramOptions.zt = (typeof paramOptions.zt == "undefined") ? null : paramOptions.zt;
        var options = {
            panelWidth: 630,
            idField: 'id',
            textField: 'jhbh',
            fitColumns: true,
            pagination: true,//是否分页
            rownumbers: true,//序号
            collapsible: false,//是否可折叠的
            fit: true,//自动大小
            pageSize: paramOptions.page,//每页显示的记录条数，默认为10
            url: $.webPath() + '/jhgl/wzjhgl/wzjhCreateHtList?ssgsId=' + paramOptions.ssgsId + "&zt=" + paramOptions.zt,
            columns: [
                [
                    {field: 'jhbh', title: '计划编号', width: 100},
                    {field: 'xqnf', title: '计划年份', width: 60},
                    {field: 'xqyf', title: '计划月份', width: 60},
                    {field: 'gys_qc', title: '供应商', width: 80},
                    {field: 'kh_qc', title: '客户', width: 80},
                    {field: 'sbgs_qc', title: '申报公司', width: 80},
                    {field: 'sbbm_qc', title: '申报部门', width: 80},
                    {field: 'zdsj', title: '制单时间', width: 80}
                ]
            ]
        };
        $.extend(options, paramOptions);
        $(this).combogrid(options);
    },
    //type:自购物资计划Zgwzjh  统配物资计划Tpwzjh
    wzjhForZjjhCombogrid: function (paramOptions) {
        paramOptions.type = (typeof paramOptions.type == "undefined") ? 'Zgwzjh' : paramOptions.type;
        paramOptions.page = (typeof paramOptions.page == "undefined") ? 10 : paramOptions.page;
        paramOptions.ssgsId = (typeof paramOptions.ssgsId == "undefined") ? null : paramOptions.ssgsId;
        paramOptions.zt = (typeof paramOptions.zt == "undefined") ? null : paramOptions.zt;
        var options = {
            panelWidth: 630,
            idField: 'id',
            textField: 'jhbh',
            fitColumns: true,
            pagination: true,//是否分页
            rownumbers: true,//序号
            collapsible: false,//是否可折叠的
            fit: true,//自动大小
            pageSize: paramOptions.page,//每页显示的记录条数，默认为10
            url: $.webPath() + '/jhgl/wzjhgl/wzjhCreateZjjhList?type=' + paramOptions.type + "&ssgsId=" + paramOptions.ssgsId + "&zt=" + paramOptions.zt,
            columns: [
                [
                    {field: 'jhbh', title: '计划编号', width: 100},
                    {field: 'xqnf', title: '计划年份', width: 60},
                    {field: 'xqyf', title: '计划月份', width: 60},
                    {field: 'gys_qc', title: '供应商', width: 80},
                    {field: 'kh_qc', title: '客户', width: 80},
                    {field: 'sbgs_jc', title: '申报公司', width: 80},
                    {field: 'sbbm_jc', title: '申报部门', width: 80},
                    {field: 'zdsj', title: '制单时间', width: 80}
                ]
            ]
        };
        $.extend(options, paramOptions);
        $(this).combogrid(options);
    },

    //协议combogrid
    xyCombogrid: function (paramOptions) {
        //协议类型：传types数组；不传参数：全部，cgxy：采购协议，xsxy：销售协议，sfxy：三方协议）
        //所属公司：ssgsId；
        //审批状态：spzt；（已保存，已提交，已审批）   ybc ytj ysp
        paramOptions.page = (typeof paramOptions.page == "undefined") ? 10 : paramOptions.page;
        var options = {
            panelWidth: 700,
            idField: 'id',
            textField: 'xyhm',
            fitColumns: true,
            pagination: true,//是否分页
            rownumbers: true,//序号
            collapsible: false,//是否可折叠的
            fit: true,//自动大小
            pageSize: paramOptions.page,//每页显示的记录条数，默认为10
            url: $.webPath() + '/jhgl/xygl/otherXyList',
            columns: [
                [
                    {field: 'xyhm', title: '协议编号', width: 200},
                    {field: 'type', title: '协议类型', width: 100, formatter: function (value, row, index) {
                        switch (value) {
                            case 'cgxy':
                                return "采购协议";
                            case 'xsxy':
                                return "销售协议";
                            case 'sfxy':
                                return "三方协议";
                            default:
                                return "";
                        }
                    }
                    },
                    {field: 'gys_qc', title: '供应商', width: 80},
                    {field: 'kh_qc', title: '客户', width: 80},
                    {field: 'dbf_qc', title: '担保方', width: 80},
                    {field: 'nxyl', title: '年协议量', width: 80},
                    {field: 'yxyl', title: '月协议量', width: 80},
                    {field: 'nbgs_qc', title: '公司名称', width: 80},
                    {field: 'zdsj', title: '制单时间', width: 80}
                ]
            ]
        };
        $.extend(options, paramOptions);
        $(this).combogrid(options);
    },

    yjwzbmCombobox: function (paramOptions) {
        var options = {
            url: $.webPath() + "/sys/wzbm/findAllYjwzbm",
            valueField: 'id',
            textField: 'name',
            multiple: false,
            panelHeight: '300',
            formatter: function (row) {
                var opts = $(this).combobox('options');
                return "(" + row["code"] + ")" + row[opts.textField];
            }
        };
        $.extend(options, paramOptions);
        $(this).combobox(options);
    },

    wzdlCombobox: function (paramOptions) {
        var options = {
            url: $.webPath() + "/sys/wzbm/findAllYjwzbm",
            valueField: 'code',
            textField: 'name',
            multiple: false,
            panelHeight: '300',
            formatter: function (row) {
                var opts = $(this).combobox('options');
                return "(" + row["code"] + ")" + row[opts.textField];
            }
        };
        $.extend(options, paramOptions);
        $(this).combobox(options);
    }

});

